//
//  HomeHeadView.m
//  Base_App
//
//  Created by Yutian Duan on 2019/5/27.
//  Copyright © 2019年 Wanwin. All rights reserved.
//

#import "HomeHeadView.h"
#import "CardCollectionView.h"

@interface HomeHeadView () {
  ///！ 背景
  UIImageView *bgImageView;
  ///! 轮播图
  
}
//! 油吉申请
@property (nonatomic, strong) UIImageView *cardImageView;

@property (nonatomic, strong) CardCollectionView *cardCollectionView;

@end

@implementation HomeHeadView

///! 登记图
- (UIImageView *)cardImageView {
  if (!_cardImageView) {
    
    //!
    _cardImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, bgImageView.yt_centerY + 20, ScreenWidth, (ScreenWidth - 0) * 0.5)];
    _cardImageView.image = [UIImage imageNamed:@"Home_login"];
    _cardImageView.contentMode = UIViewContentModeScaleAspectFill;
    _cardImageView.layer.masksToBounds = YES;
    _cardImageView.layer.cornerRadius = 8.0f;
    _cardImageView.userInteractionEnabled = YES;
    [self addSubview:_cardImageView];
    
    UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickLogin)];
    [_cardImageView addGestureRecognizer:singleTap];
    
    CGFloat tipTop = 50;
    if (IS_IPHONE5) {
      tipTop = 35;
    }
    
    //!
    UILabel *tipLabel = [[UILabel alloc] initWithFrame:CGRectMake(40, tipTop, 160, 20)];
    tipLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:13.0f];
    tipLabel.textAlignment = NSTextAlignmentLeft;
    tipLabel.text = YTLocalizedString(@"立即登记成为会员");
    tipLabel.textColor = [UIColor whiteColor];
    [_cardImageView addSubview:tipLabel];
    
    //!
    UILabel *contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(tipLabel.yt_left, tipLabel.yt_bottom, 300, 36)];
    contentLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:18.0f];
    contentLabel.textAlignment = NSTextAlignmentLeft;
    contentLabel.text = YTLocalizedString(@"尊享极高折扣商户优惠");
    contentLabel.textColor = [UIColor whiteColor];
    [_cardImageView addSubview:contentLabel];
    
    //!
    UILabel *detailLabel = [[UILabel alloc] initWithFrame:CGRectMake(contentLabel.yt_left, contentLabel.yt_bottom, contentLabel.yt_width, 20)];
    detailLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:13.0f];
    detailLabel.textAlignment = NSTextAlignmentLeft;
    detailLabel.text = YTLocalizedString(@"著数及入油记录一览无遗");
    detailLabel.textColor = DEF_GRAY;
    [_cardImageView addSubview:detailLabel];
    //


    

  }
  return _cardImageView;
}


///! 轮播图
- (CardCollectionView *)cardCollectionView {
  if (!_cardCollectionView) {
    CGSize item = CGSizeMake(ScreenWidth - 40, 50 + (ScreenWidth - 40) * IMAGEPRO + 60);
    
    CardCollectionViewLayout *layout = [[CardCollectionViewLayout alloc] initWithItemSize:item];
    layout.minimumLineSpacing = 10;

    _cardCollectionView = [[CardCollectionView alloc] initWithFrame:CGRectMake(0, self.cardImageView.yt_bottom, ScreenWidth, item.height) collectionViewLayout:layout];
    [self addSubview:_cardCollectionView];
    
  }
  return _cardCollectionView;
}

- (instancetype)initWithFrame:(CGRect)frame {
  self = [super initWithFrame:frame];
  if (self) {
    self.backgroundColor = HEXCOLOR(0xf7f8fc);
    [self setupViews];
  }
  return self;
}

- (void)setupViews {
  
  //! 背景图片
  bgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth,  ScreenWidth * 0.615)];
  bgImageView.contentMode = UIViewContentModeScaleAspectFit;
  bgImageView.image = [UIImage imageNamed:@"Home_BgImage"];
  [self addSubview:bgImageView];
  
  //！
  UILabel *welcomeLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, bgImageView.yt_centerY - 40, 120, 40)];
  welcomeLabel.text = YTLocalizedString(@"欢迎");
  welcomeLabel.textColor = [UIColor whiteColor];
  welcomeLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:18.0f];
  [bgImageView addSubview:welcomeLabel];
  
  CGFloat logoH = 13;
  if (IS_IPHONE5) {
    logoH = 10;
  }
  
  //! logo
  UIImageView *logoView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, logoH * 14, logoH)];
  logoView.image = [UIImage imageNamed:@"Home_logo"];
  logoView.contentMode = UIViewContentModeScaleAspectFit;
  [bgImageView addSubview:logoView];
  logoView.yt_centerY = welcomeLabel.yt_centerY;
  logoView.yt_right = bgImageView.yt_right - 20;
  
  //!
  UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(20, self.cardCollectionView.yt_bottom + 20, ScreenWidth - 40, 0.8)];
  lineView.backgroundColor = THEME_GRAY;
  [self addSubview:lineView];
  
  ///!
  UILabel *newTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(lineView.yt_left, lineView.yt_bottom, lineView.yt_width, 40)];
  newTitleLabel.text = YTLocalizedString(@"最新消息");
  newTitleLabel.textAlignment = NSTextAlignmentLeft;
  newTitleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:18.0f];
  newTitleLabel.textColor = [UIColor blackColor];
  [self addSubview:newTitleLabel];
  
  self.yt_height = newTitleLabel.yt_bottom;

}

- (void)reloadData {
  ///!
  self.cardCollectionView.imageArray = @[@"Home_CarPrice",@"Home_CarPrice",@"Home_CarPrice"];
  self.cardCollectionView.currentIndex = 1;
  [self.cardCollectionView reloadData];
  [self.cardCollectionView  scrollToItemAtIndexPath:[NSIndexPath indexPathForRow:self.cardCollectionView.currentIndex inSection:0] atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:NO];


}

#pragma mark - function
- (void)clickLogin {
  if (self.clickLoginBlock) {
    self.clickLoginBlock();
  }
  
}

@end
